<template>
  <div>
    <header>
      <n-bar></n-bar>
      <!-- logo -->
      <div class="header_box">
        <!-- 推荐 -->
        <div class="recommend">
          <ul>
            <li>
              <a href=" ">商品</a>
            </li>
            <li>
              <a href=" ">评价</a>
            </li>
            <li>
              <a href=" ">详情</a>
            </li>
            <li>
              <a href=" ">推荐</a>
            </li>
          </ul>
        </div>
      </div>
    </header>
    <div class="detail">
      <div class="banner">
        <img :src="goodsinfo.img" alt="" />
        <p class="iconfont icon-fenxiang"></p>
        <p>8/8</p>
      </div>
      <div class="banner_bot">
        <div class="first">
          <p>
            <span>￥</span>
            <span>{{ goodsinfo.price }}</span>
            <del>￥{{ goodsinfo.market_price }}</del>
          </p>
          <p>
            <span class="iconfont icon-shoucang1"></span>
            <span>收藏</span>
          </p>
        </div>
        <p>{{ goodsinfo.goodsname }}</p>
        <p v-html="goodsinfo.description"></p>
        <p>11.11限时299元起</p>
        <p>
          <span>此商品于2020-11-11,00点结束闪购特卖，</span>
          <span>
            <a href=" ">查看</a>
            <i class="iconfont icon-arrow-right"> </i>
          </span>
        </p>
      </div>
      <div class="bot">
        <div class="lingquan">
          <div class="left">
            <h4>领券</h4>
          </div>
          <div class="right">
            <span>
              <img src="../assets/images/奖券.png" alt="" />
              <i>300</i>
            </span>
            <span>
              <img src="../assets/images/奖券.png" alt="" />
              <i>50</i>
            </span>
            <span>
              <img src="../assets/images/奖券.png" alt="" />
              <i>10</i>
            </span>
          </div>
        </div>
        <div class="fenqi">
          <div class="left">
            <h4>分期</h4>
          </div>
          <div class="right">
            <p>可选3/6/12期</p>
            <span class="iconfont icon-arrow-right"></span>
          </div>
        </div>
      </div>
    </div>
    <footer>
      <!-- 提交栏 -->
      <van-goods-action>
        <van-goods-action-icon icon="chat-o" text="客服" color="#ee0a24" />
        <van-goods-action-icon icon="cart-o" text="购物车" />
        <van-goods-action-icon icon="star" text="已收藏" color="#ff5000" />
        <van-goods-action-button
          type="warning"
          text="加入购物车"
          @click="add()"
        />
        <van-goods-action-button type="danger" text="立即购买" @click="goBuy" />
      </van-goods-action>
    </footer>
  </div>
</template>

<script>
import { getDetail, cartAdd } from "../requset/app";
import { mapGetters } from "vuex";
import { Dialog } from "vant";
export default {
  data() {
    return {
      goodsinfo: {}, //获取一个商品信息
    };
  },
  computed: {
    ...mapGetters(["getUserInfo"]),
  },
  mounted() {
    getDetail({
      id: this.$route.query.id,
    }).then((res) => {
      // console.log(res, "商品详情");
      if (res.code == 200) {
        this.goodsinfo = res.list[0];
        // console.log(this.goodsinfo);
      }
    });
  },
  methods: {
    // 跳转订单页
    goBuy() {
      this.$router.push("/order");
    },
    // 点击加入购物车
    add() {
      if (this.getUserInfo) {
        // console.log("准备加入购物车");
        cartAdd({
          uid: this.getUserInfo.uid,
          goodsid: this.goodsinfo.id,
          num: 1,
        }).then((res) => {
          // console.log(res, "购物车");
          if (res.code == 200) {
            this.$router.push("/cart");
          }
        });
      } else {
        console.log("未登录");
        Dialog.confirm({
          message: "未登录，不能加入购物车",
        })
          .then(() => {
            this.$router.push("/login");
          })
          .catch(() => {});
      }
    },
  },
};
</script>

<style scoped>
/* 头部 */
header {
  background-color: #ff6040;
  box-shadow: 0 0.02rem 0.06rem 0 rgba(255, 149, 128, 0.5);
  box-sizing: border-box;
}

/* 顶部信息 */
header .top_box {
  height: 0.44rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.06rem 0 0.17rem;
  box-sizing: border-box;
}

header .top_box > a span {
  font-size: 0.17rem;
  color: #ffffff;
}

header .top_box h2 {
  opacity: 0.8;
  font-size: 0.17rem;
  color: #ffffff;
  margin-left: 0.23rem;
}

header .top_box .more {
  width: 0.87rem;
  height: 0.32rem;
  background: rgba(255, 119, 51, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0.405rem;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

header .top_box .more .line {
  width: 1px;
  height: 0.19rem;
  background: rgba(255, 255, 255, 0.25);
}

header .top_box .more a span {
  font-size: 0.19rem;
  opacity: 0.8;
  color: #ffffff;
}

/* 推荐 */
.header_box .recommend ul {
  height: 0.32rem;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.header_box .recommend ul li a {
  font-size: 0.14rem;
  color: #fff;
}

.header_box .recommend ul li:nth-child(1) a {
  font-size: 0.16rem;
  font-weight: bold;
}

.header_box .recommend ul li:nth-child(1) {
  position: relative;
}

.header_box .recommend ul li:nth-child(1) a::after {
  content: "";
  width: 0.2rem;
  height: 0.02rem;
  background: #ffffff;
  border-radius: 0.01rem;
  position: absolute;
  bottom: -0.04rem;
  left: 0.06rem;
}
.detail .banner img {
  width: 3.75rem;
  height: 3.75rem;
}
.detail .banner p::before {
  display: block;
  width: 0.24rem;
  height: 0.24rem;
  text-align: center;
  line-height: 0.24rem;
  color: #fff;
  background: rgba(51, 51, 51, 0.8);
  border-radius: 50%;
  position: absolute;
  right: 0.1rem;
  top: 1.3rem;
}
.detail .banner p:last-child {
  height: 0.18rem;
  width: 0.4rem;
  text-align: center;
  line-height: 0.18rem;
  background: rgba(51, 51, 51, 0.8);
  border-radius: 0.18rem;
  position: absolute;
  right: 0.1rem;
  bottom: 1.8rem;
  color: #fff;
}

.detail .banner_bot {
  display: flex;
  flex-direction: column;
  padding-left: 0.1rem;
  background-color: #fff;
  padding-bottom: 0.08rem;
}

.detail .banner_bot .first {
  display: flex;
  justify-content: space-between;
}

.detail .banner_bot .first p:nth-child(1) {
  font-size: 0.14rem;
  color: #999999;
}

.detail .banner_bot .first p:nth-child(1) span:nth-child(1) {
  color: #ff6040;
}

.detail .banner_bot .first p:nth-child(1) span:nth-child(2) {
  font-size: 0.3rem;
  color: #ff6040;
}

.detail .banner_bot .first p:nth-child(2) span {
  font-size: 0.1rem;
  color: #ff6040;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.detail .banner_bot .first p:nth-child(2) {
  margin: 0.05rem 0.1rem 0 0;
}

.detail .banner_bot p:nth-of-type(1) {
  font-size: 0.16rem;
  color: #333333;
  margin-top: 0.1rem;
}

.detail .banner_bot p:nth-of-type(2) {
  font-size: 0.14rem;
  color: #999999;
  margin-top: 0.05rem;
}
.detail .banner_bot p:nth-of-type(2) >>> img {
  width: 100%;
}

.detail .banner_bot p:nth-of-type(3) {
  width: 0.89rem;
  height: 0.2rem;
  background: #ff8066;
  text-align: center;
  line-height: 0.2rem;
  font-size: 0.1rem;
  color: #ffffff;
  margin-top: 0.12rem;
}

.detail .banner_bot p:nth-of-type(4) {
  width: 3.55rem;
  height: 0.2rem;
  background: #f2f2f2;
  margin-top: 0.1rem;
  line-height: 0.2rem;
  padding: 0 0.03rem 0 0.05rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
}

.detail .banner_bot p:nth-of-type(4) span a {
  font-size: 0.1rem;
  color: #ff6040;
  font-weight: bold;
}

.detail .banner_bot p:nth-of-type(4) span i {
  font-size: 0.06rem;
  color: #ff6040;
  font-weight: bold;
}

.detail .banner_bot p:nth-of-type(4) span:nth-child(1) {
  font-size: 0.1rem;
  color: #999999;
}

.detail .banner_bot p:nth-of-type(4) span:nth-child(2) {
  font-size: 0.1rem;
  color: #ff6040;
}

.detail .bot {
  margin-top: 0.1rem;
  background-color: #fff;
  /* 解决这个被遮盖且滑动滚动条也看不见得问题 */
  margin-bottom: 0.8rem;
}

.detail .bot .lingquan {
  display: flex;
  width: 3.75rem;
}

.detail .bot .lingquan .left h4 {
  width: 0.29rem;
  height: 0.12rem;
  font-size: 0.12rem;
  color: #333333;
  padding: 0.22rem 0.2rem 0.11rem 0.1rem;
}

.detail .bot .lingquan .right {
  width: 3.2rem;
  padding-top: 0.235rem;
  padding-bottom: 0.09rem;
  border-bottom: 0.005rem solid #cccccc;

  display: flex;
}

.detail .bot .lingquan .right span:nth-child(1) {
  position: relative;
  display: flex;
  align-items: center;
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(1) img {
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(1) i {
  position: absolute;
  font-size: 0.1rem;
  color: #663014;
  top: 0rem;
  left: 0.1rem;
}

.detail .bot .lingquan .right span:nth-child(2) {
  position: relative;
  margin-left: 0.1rem;
  display: flex;
  align-items: center;
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(2) img {
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(2) i {
  position: absolute;
  font-size: 0.1rem;
  color: #663014;
  top: 0rem;
  left: 0.1rem;
}

.detail .bot .lingquan .right span:nth-child(3) {
  position: relative;
  margin-left: 0.1rem;
  display: flex;
  align-items: center;
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(3) img {
  width: 0.39rem;
  height: 0.16rem;
}

.detail .bot .lingquan .right span:nth-child(3) i {
  position: absolute;
  font-size: 0.1rem;
  color: #663014;
  top: -0.03rem;
  top: 0;
  left: 0.1rem;
}

.detail .bot .fenqi {
  display: flex;
  padding-bottom: 0.05rem;
}

.detail .bot .fenqi .left h4 {
  width: 0.29rem;
  height: 0.12rem;
  font-size: 0.12rem;
  color: #333333;
  padding: 0.16rem 0.2rem 0.05rem 0.1rem;
}

.detail .bot .fenqi .right {
  width: 3.75rem;
  padding-top: 0.16rem;
  display: flex;
  justify-content: space-between;
}

.detail .bot .fenqi .right p {
  font-size: 0.12rem;
  color: #666666;
}

.detail .bot .fenqi .right span {
  font-size: 0.08rem;
}
footer {
  height: 0.83rem;
  display: flex;
  position: fixed;
  bottom: -0.07rem;
  justify-content: space-between;
  background: #ffffff;
  box-shadow: 0 -0.05rem 0.1rem 0 rgba(204, 204, 204, 0.2), 0 0 0 0 #cccccc;
}

footer .box {
  display: flex;
}

footer .left {
  width: 1.55rem;
  height: 0.49rem;
}

footer ul {
  display: flex;
  justify-content: space-evenly;
}

footer .left ul li {
  display: flex;
  flex-direction: column;
}

footer .left ul li a span {
  font-size: 0.1rem;
  color: #333333;
}

footer .left ul li > span {
  font-size: 0.2rem;
  color: #000;
}

footer .right {
  display: flex;
}

footer .right a {
  width: 1.1rem;
  height: 0.49rem;
  text-align: center;
  line-height: 0.49rem;
}

footer .right a:nth-child(1) {
  font-size: 0.16rem;
  color: #663014;
  background: #ffcc66;
}

footer .right a:nth-child(2) {
  font-size: 0.16rem;
  color: #ffffff;
  background: #ff6040;
}

footer .foot_box {
  width: 1.34rem;
  height: 0.34rem;
  position: absolute;
  bottom: 0.15rem;
  left: 50%;
  transform: translateX(-50%);
}

footer .foot_box img {
  width: 1.34rem;
  height: 0.3rem;
  margin-top: 0.1rem;
}
</style>
